package com.hp.common.dauth;

import com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;

import javax.annotation.PostConstruct;
import java.util.List;

@AutoConfigureAfter(PageHelperAutoConfiguration.class)
public class DataScopeConfig {

    @Autowired
    private List<SqlSessionFactory> sqlSessionFactoryList;

    @PostConstruct
    public void addDataAuthInterceptor(){
        DataScopeInterceptor interceptor = new DataScopeInterceptor();
        for (SqlSessionFactory sqlSessionFactory : sqlSessionFactoryList){
            sqlSessionFactory.getConfiguration().addInterceptor(interceptor);
        }
    }
}
